var member_id = '',
	order_id,
	goods_id,
	ws,
	mid;
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');
	ws = plus.webview.currentWebview();
	order_id = ws.xid;
	spage = ws.spage;
	plus.nativeUI.showWaiting('加载中...');
	$.ajax({ 
		type:"post", 
		url:apiRoot+"?act=member_campus&op=onedetails",
		data:{member_id:member_id,xid:order_id},
		dataType:'json',
		success:function(data){ 
			console.log(JSON.stringify(data));
			if(data.code == 200){
//				console.log(member_id +'--'+ data.datas.member_id);
				switch(data.datas.order_status){
					case '0':
							$('.campus_tit').eq(0).css('display','block');
							$('.zhuangtai2').css('display','block');
							//赋id值
							$('.campus_tit').eq(0).find('.quxiao').attr('data-xid',data.datas.xid);
					break;
					case '1':
							$('.campus_tit').eq(1).css('display','block');
							$('.touxiang').attr('src',(data.datas.recipient.member_avatar != null?(user_pic + data.datas.recipient.member_avatar):"../public/img/pic_img.jpg"));
							$('.member_naem').text('接单人：' + data.datas.recipient.member_truename);
							$('.zhuangtai1').css('display','block');
							//赋id值
							$('.campus_tit').eq(1).find('.operation').attr('data-xid',data.datas.xid);
							$('.campus_tit').eq(1).find('.operation').attr('data-mid',data.datas.recipient.member_id);
							$('.campus_tit').eq(1).find('.operation').attr('data-price',data.datas.remuneration);
							$('.campus_tit').eq(1).find('.quxiao').attr('data-xid',data.datas.xid);
					break;
					case '2':
							$('.campus_tit').eq(2).css('display','block');
							$('.touxiang').attr('src',(data.datas.recipient.member_avatar != null?(user_pic + data.datas.recipient.member_avatar):"../public/img/pic_img.jpg"));
							$('.member_naem').text('接单人：' + data.datas.recipient.member_truename);
							$('.zhuangtai1').css('display','block');
					break;
					case '3':
							$('.campus_tit').eq(3).css('display','block');
							$('.zhuangtai3').css('display','block');
					break;
					case '4':
							$('.campus_tit').eq(4).css('display','block');
							$('.touxiang').attr('src',(data.datas.recipient.member_avatar != null?(user_pic + data.datas.recipient.member_avatar):"../public/img/pic_img.jpg"));
							$('.member_naem').text('接单人：' + data.datas.recipient.member_truename);
							$('.zhuangtai1').css('display','block');
					break;
				
				}
				
				$('.campus_time').text(data.datas.qtime);
				$('.campus_title').text(data.datas.title);
				$('.campus_datatime').text(data.datas.targettime);
				$('.campus_lxr').text(data.datas.contacts);
				$('.campus_price').text('￥' + data.datas.remuneration);
				$('.campus_address').text(data.datas.address);
				$('.campus_tel').text(data.datas.publisher.member_name);
				$('.campus_xq').text(data.datas.demand);
				if(data.datas.campus_pics){	
					var html = '';
					$.each(data.datas.campus_pics, function(k,v) {
						html += '<img src="'+ app_pic + data.datas.publisher.member_id + '/' + v +'" data-preview-src="" data-preview-group="1"/>';
					});
					$('.campus_pic').html(html);
				}
			}
			plus.nativeUI.closeWaiting();
			//完成任务
			$('.operation').unbind('tap');
			$('.operation').on('tap',function(){
				var _this = $(this);
				var xid = _this.attr('data-xid');             //唯一id
				var mid = _this.attr('data-mid');				//接单用户id
				var price = _this.attr('data-price');			//报酬
//				console.log(xid+'--'+mid+'--'+price);return;
				$.ajax({
					type:"post",
					url:apiRoot + "?act=member_campus&op=order_end",
					data:{member_id:member_id,xid:xid,mid:mid,price:price},
					dataType:'json',
					success:function(data){
						console.log(JSON.stringify(data));
						if(data.code == 200){
							toast('确认任务完成成功');
							plus.webview.getWebviewById(spage).reload();
							setTimeout(function(){
								ws.close();
							},500)
						}else{
							toast(data.datas.error);
						}
					},
					error:function(e){
						error();
						
					}
				});
			})
//			
			//取消任务
			$('.quxiao').unbind('tap');
			$('.quxiao').on('tap',function(){
				var _this = $(this);
				var xid = _this.attr('data-xid');
//				console.log(apiRoot + "?act=member_campus&op=task_cancel--"+member_id+'--'+xid);return;
				$.ajax({  
					type:"post",
					url:apiRoot + "?act=member_campus&op=task_cancel",
					data:{member_id:member_id,xid:xid},
					dataType:'json',
					success:function(data){
//						console.log(JSON.stringify(data));
						if(data.code == 200){
							toast('取消成功');
							plus.webview.getWebviewById(spage).reload();
							setTimeout(function(){
								ws.close();
							},500)
						}else{
							toast(data.datas.error);
						}
					},
					error:function(e){
						console.log(JSON.stringify(e));
						
					}
				});
			})
		},  
		error:function(e){
			plus.nativeUI.closeWaiting();
			toast('连接失败！');
		}
	});
},false);